<template>
  <div style="padding:30px;">
    <Breadcrumb />
    <el-card style="margin-top:15px;">
      <div id="main" :style="{width: '800px', height: '500px'}" />
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
import { getReports } from '@/api/data.js'

export default {
  data() {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        grid: {
          left: '5%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },

        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            boundaryGap: false,
            axisLine: {
              show: true
            }
          }
        ]
      }
    }
  },
  // 调用
  mounted() {
    this.getEcharts()
  },
  methods: {
    async getEcharts() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'))
      const res = await getReports()
      const option = _.merge(res, this.options)

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    }
  }

}
</script>

<style scoped lang='less'>

</style>

